package com.dou.cloud.bridge.redis.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 * @Author daizl
 * @Date 2024 05 13 13 27
 **/
@NoArgsConstructor
@AllArgsConstructor
@Getter
public enum RedissonEnum {

    TRY_LOCK(1,"尝试锁"),
    FAIR_LOCK(2,"公平锁"),
    READ_LOCK(3,"读锁"),
    WRITE_LOCK(4,"写锁"),
    SEMAPHORE(5,"信号量"),
    COUNTDOWN_LATCH(6,"闭锁"),
    PERMIT_EXPIRABLE_SEMAPHORE(7,"可过期性信号量")
    ;

    private Integer type;

    private String mapName;


    public static String getMapName(Integer type) {
        for (RedissonEnum value : RedissonEnum.values()) {
            if (Objects.equals(value.getType(), type)) {
                return value.getMapName();
            }
        }
        return null;
    }

    public static Integer getType(String mapName) {
        for (RedissonEnum value : RedissonEnum.values()) {
            if (Objects.equals(value.getMapName(), mapName)) {
                return value.getType();
            }
        }
        return null;
    }
}
